﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QuickDrawScreen
{
    public partial class MainForm : Form
    {
        //全局窗口坐标
        private Point _frmPoint;

        public static Form MainFormInstance;
        public MainForm()
        {
            InitializeComponent();

            var k_hook = new KeyboardHook();
            k_hook.KeyDownEvent += new KeyEventHandler(hook_KeyDown);//钩住键按下 
            k_hook.Start();//安装键盘钩子

            this.TopMost = true;
            MainFormInstance = this;
            //无边框
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            //不出现在任务栏
            this.ShowInTaskbar = false;

            _frmPoint = new Point();

        }

        private void hook_KeyDown(object sender, KeyEventArgs e)
        {
            //判断按下的键（Alt + A） 

            if (e.KeyValue == (int)Keys.Enter && (int)Control.ModifierKeys == (int)Keys.Control)
            {
                ToDrawForm();

            }
        }


        private void MainForm_Load(object sender, EventArgs e)
        {
            var screenWidth = Screen.PrimaryScreen.Bounds.Width;
            var screenHeight = Screen.PrimaryScreen.Bounds.Height;
            this.Left = screenWidth - 250;
            this.Top = 50;

            this.BackColor = Color.LightPink;
            this.TransparencyKey = Color.White;
            this.Opacity = 0.5;

            this.MouseMove += MainForm_MouseMove;

        }

        void MainForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                Point myPosittion = MousePosition;
                myPosittion.Offset(-_frmPoint.X, -_frmPoint.Y);
                Location = myPosittion;
            }
        }

        void MainForm_MouseDown(object sender, MouseEventArgs e)
        {
            _frmPoint.X = e.X;
            _frmPoint.Y = e.Y;
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            ToDrawForm();
        }

        private void Quit_Click(object sender, EventArgs e)
        {
            this.Close();
            this.Dispose();
            Application.Exit();
        }

        private void Video_Click(object sender, EventArgs e)
        {
            MessageBox.Show("正在开发中...");
        }

        public void ToDrawForm()
        {
            DrawForm drawForm = new DrawForm();
            MainForm.MainFormInstance.Hide();
            drawForm.CaptureScreen();//显示子窗体
        }
    }
}
